//  this library.
import 'package:hktk_app/ienum/home/column_type_enum.dart';

/// 栏目数据类型，金刚区，名师推荐相关
class ColumnModel {
  String? createdTime;
  String? modifyTime;
  String? createdBy;
  String? modifyBy;
  String? id;
  String? name;
  String? serverName;
  int? categoryId;
  ColumnTypeEnum? type;
  String? position;
  int? sort;
  int? groupId;
  bool? show;

  // 科目名
  String? categoryName;

  // 是否已购买
  bool? soldFlag;
  int? dataCount;

  // 配置关系
  List<Configs>? configs;
  int? price;

  // 图标路径，自定义的
  String? iconUrl;

  ColumnModel({
    this.createdTime,
    this.modifyTime,
    this.createdBy,
    this.modifyBy,
    this.id,
    this.name,
    this.serverName,
    this.categoryId,
    this.type,
    this.position,
    this.sort,
    this.groupId,
    this.show,
    this.categoryName,
    this.soldFlag,
    this.dataCount,
    this.configs,
    this.price,
    this.iconUrl,
  });

  ColumnModel.fromJson(Map<String, dynamic> json) {
    createdTime = json['createdTime'];
    modifyTime = json['modifyTime'];
    createdBy = json['createdBy'];
    modifyBy = json['modifyBy'];
    id = json['id'];
    name = json['name'];
    serverName = json['serverName'];
    categoryId = json['categoryId'];
    if (json["type"] != null) {
      type = ColumnTypeEnum.getColumnType(json['type']);
    }
    position = json['position'];
    sort = json['sort'];
    groupId = json['groupId'];
    show = json['show'];
    categoryName = json['categoryName'];
    soldFlag = json['soldFlag'];
    dataCount = json['dataCount'];
    if (json['configs'] != null) {
      configs = <Configs>[];
      json['configs'].forEach((v) {
        configs!.add(Configs.fromJson(v));
      });
    }
    price = json['price'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['createdTime'] = createdTime;
    data['modifyTime'] = modifyTime;
    data['createdBy'] = createdBy;
    data['modifyBy'] = modifyBy;
    data['id'] = id;
    data['name'] = name;
    data['serverName'] = serverName;
    data['categoryId'] = categoryId;
    if (type != null) {
      data['type'] = type!.name;
    }
    data['position'] = position;
    data['sort'] = sort;
    data['groupId'] = groupId;
    data['show'] = show;
    data['categoryName'] = categoryName;
    data['soldFlag'] = soldFlag;
    data['dataCount'] = dataCount;
    if (configs != null) {
      data['configs'] = configs!.map((v) => v.toJson()).toList();
    }
    data['price'] = price;
    return data;
  }
}

class Configs {
  // 关系id
  String? id;

  // 是否免费
  bool? isFree;
  int? sort;

  Configs({this.id, this.isFree, this.sort});

  Configs.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    isFree = json['isFree'];
    sort = json['sort'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['isFree'] = isFree;
    data['sort'] = sort;
    return data;
  }
}
